
from typing import Optional

class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


# 相交时的数学本质 两边走的路是一样的

class Solution:
    def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> Optional[ListNode]:

        A, B = headA, headB
        while A != B:

            A = A.next if A else headB
            B = B.next if B else headA

        return A




